
class Person {

}

class Child extends Person { }

let p1 = new Person
let c1 = new Child


console.log(p1 instanceof Person) // true 

console.log(c1 instanceof Person) // true 

let obj = {}

/***
 * 特性： 是否为right或right子类的实例  循环向上查找
 */


console.log(obj instanceof Object)



function MyInstanceOf(target, right) {
    let currPto = target.__proto__ // 当前元素的原型
    let parentPto = right.prototype // 父元素的原型

    while (currPto) {
        if (currPto === parentPto) return true
        currPto = currPto.__proto__
    }

    return false
}

console.log(MyInstanceOf(p1, Person)) // true
console.log(MyInstanceOf(c1, Person))
console.log(MyInstanceOf(obj, Object)) // true
